package com.zh.mediacommon.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;

public class OrderUtil {
    private static final AtomicLong sequence = new AtomicLong(0);

    // 生成订单ID的方法
    public static String generateOrderId() {
        // 获取当前时间戳
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String timestamp = dateFormat.format(new Date());

        // 生成一个随机数
        Random random = new Random();
        int randomNumber = random.nextInt(9999);

        // 使用AtomicLong生成一个自增的序列号
        long sequenceNumber = sequence.getAndIncrement();

        // 组合时间戳、随机数和序列号生成订单ID
        return timestamp + String.format("%04d", randomNumber) + String.format("%04d", sequenceNumber % 10000);
    }
    public static String getSubject(){
        return "Media-service";
    }

    public static String generateBizContent(String orderId,Integer price){
            return "{\"out_trade_no\":\"" + orderId+ "\","
                    + "\"total_amount\":\"" + price.toString() + "\","
                    + "\"subject\":\"" + OrderUtil.getSubject()+ "\","
                    + "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}";
    }
}
